package cn.xiaohuodui.res;

import cn.xiaohuodui.constant.ErrorCodeDefine;

/**
 * Json信息返回
 *
 * @author Fang
 * @create 2017-04-06 下午4:50
 */
public class JsonRes<T> {
    private T data;
    private Integer code;
    private String msg;
    private static final JsonRes success = new JsonRes(200, "success");

    public JsonRes() {
    }

    private JsonRes(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private JsonRes(int code,T data){
        this.code = code;
        this.data = data;
    }

    private JsonRes(int code,String msg,T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public static <T> JsonRes<T> createBySuccess(){
        return new JsonRes<T>(ErrorCodeDefine.DEFAULT_SUCCESS.getCode(),ErrorCodeDefine.DEFAULT_SUCCESS.getDesc());
    }

    public static <T> JsonRes<T> createBySuccessMessage(String msg){
        return new JsonRes<T>(ErrorCodeDefine.DEFAULT_SUCCESS.getCode(),msg);
    }


    public static <T> JsonRes<T> createBySuccessData(T data){
        return new JsonRes<T>(ErrorCodeDefine.DEFAULT_SUCCESS.getCode(),data);
    }


    public static <T> JsonRes<T> createByError(){
        return new JsonRes<T>(ErrorCodeDefine.DEFAULT_ERROR.getCode(),ErrorCodeDefine.DEFAULT_ERROR.getDesc());
    }

    public static <T> JsonRes<T> createByErrorMessage(String errorMessage){
        return new JsonRes<T>(ErrorCodeDefine.DEFAULT_ERROR.getCode(),errorMessage);
    }

    public static <T> JsonRes<T> createByErrorCodeMessage(int errorCode,String errorMessage){
        return new JsonRes<T>(errorCode,errorMessage);
    }





    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static JsonRes success() {
        return success;
    }





}
